const WebSocket = require('ws');

console.log('Testing WebSocket connection to ws://localhost:3000');

// 测试WebSocket连接
const ws = new WebSocket('ws://localhost:3000');

ws.on('open', function open() {
  console.log('WebSocket connection established');
  
  // 发送测试消息
  const testMessage = {
    type: 'user-join',
    user: {
      id: 'test_user_123',
      name: 'Test User',
      color: '#FF0000',
      documentId: 1
    }
  };
  
  console.log('Sending test message:', testMessage);
  ws.send(JSON.stringify(testMessage));
});

ws.on('message', function message(data) {
  console.log('Received message:', data.toString());
});

ws.on('error', function error(err) {
  console.error('WebSocket error:', err);
});

ws.on('close', function close() {
  console.log('WebSocket connection closed');
});

// 5秒后关闭连接
setTimeout(() => {
  ws.close();
}, 5000);